package crp.core.faculty.domain.repositories;

import com.qwlabs.lang.C2;
import crp.core.faculty.domain.models.FacultyEntity;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Parameters;

import javax.enterprise.context.ApplicationScoped;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Stream;

import static io.quarkus.panache.common.Parameters.with;

@ApplicationScoped
public class FacultyRepository implements PanacheRepositoryBase<FacultyEntity, String> {

    public Stream<FacultyEntity> findByIds(Collection<String> ids) {
        if (C2.isEmpty(ids)) {
            return Stream.empty();
        }
        return find("id in :ids", Parameters.with("ids", ids))
                .stream();
    }

    public Optional<FacultyEntity> findByFacultyNo(String facultyNo) {
        return find("facultyNo=:facultyNo", with("facultyNo", facultyNo))
                .firstResultOptional();
    }
}
